package com.xw.kotlinlib.base

import com.xw.kotlinlib.network.TResp
import com.xw.kotlinlib.network.DataException

open class BaseFlowRepository {

    fun <T : Any> TResp<T>.asData(): T {

        val d = data
        return if (code == 200 && d != null) {
            d
        } else if (d == null) {
            throw DataException(0,"data is null")
        } else {
            throw DataException(code,msg)
        }
    }

    fun <T : Any> TResp<T>.asDataNullable(): T? {
        return if (code == 200) {
            data
        } else {
            throw DataException(code,msg)
        }
    }
}